import React, { Component } from 'react'

export default class Footer extends Component {

  handleAll = (event)=>{

    this.props.checkAllTodo(event.target.checked)
  }

  handleClearAll = () =>{
    this.props.clearAllDone()
  }
  render() {
    const { todos } = this.props
    const total = todos.length
    const doneNum = todos.reduce((pre,current)=>{
      return pre + (current.done ? 1 : 0)
    },0)
    return (
      <div className="todo-footer">
        <label>
          <input type="checkbox" checked={doneNum === total && total !==0 ? true:false} onChange={this.handleAll}/>
        </label>
        <span>
          <span>已完成{doneNum}</span> / 全部{total}
            </span>
        <button onClick={this.handleClearAll} className="btn btn-danger">清除已完成任务</button>
      </div>
    )
  }
}
